import { base64Encode } from "./index";

/**
 * 生成随机字母
 */
export const randomLetter = (num: number = 7) => {
  let str =
    "CDEFGHIJKLABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzMNABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzOPQRSTUVWXYZabcdABefghijklmnopqrstuvwxyz" +
    Date.now();

  str = base64Encode(str);

  str = str.replace(/[^a-zA-Z]/gi, "");

  const randomVal = Math.abs(Math.floor(Math.random() * str.length) - num);
  const val = str.substring(randomVal, randomVal + num);

  return val;
};
